package io.gitee.mojingjiao.day07;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class TestFiles {
    private FileVisitor<Path> visitor=new FileVisitor<Path>() {
        //visitor封装了文件处理的逻辑
        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {

            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

            PathMatcher matcher= FileSystems.getDefault().getPathMatcher("glob:**{.java,.docx}") ;
            System.out.println(matcher.matches(file));


            File file1=file.toFile();
           if( file1.length()>(1*1024*1024)){
               System.out.println(file1.getName());
           };
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    };
    @Test
    public void testListFile()throws IOException{
        long start=System.currentTimeMillis();//取当前时间的毫秒数
        File folder=new File("src\\io\\gitee\\mojingjiao");
        Files.walkFileTree(Paths.get("src\\io\\gitee\\mojingjiao"),visitor);
       long end=System.currentTimeMillis();
        System.out.println("耗时："+(end-start));
    }











}
